package zj.it.bhne.gridengineeringsurvey.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import zj.it.bhne.gridengineeringsurvey.BaseActivity;
import zj.it.bhne.gridengineeringsurvey.R;
import zj.it.bhne.gridengineeringsurvey.myutils.KeyBorderUtils;
public class RegisterActivityMy extends BaseActivity implements View.OnClickListener {
    private TextView mTimeTv;
    private LinearLayout mOverView;
    private EditText mPhoneEditor;
    private ImageView mPhoneDeleted;
    //点击记时短信时间
    private CountDownTimer tirmer = new CountDownTimer(60000, 1000) {
        @SuppressLint("SetTextI18n")
        @Override
        public void onTick(long millisUntilFinished) {
            mTimeTv.setEnabled(false);
            mTimeTv.setText((millisUntilFinished / 1000) + " s");
        }

        @Override
        public void onFinish() {
            mTimeTv.setEnabled(true);
            mTimeTv.setText("获取验证码");
        }
    };
    private ImageView mPassDeleted,mPassReDeleted;
    private EditText mPasseEditor,mRePassEditor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_register1);
        initView();
        initLisenner();
    }

    private void initLisenner() {
        mPhoneDeleted.setOnClickListener(this);
        mOverView.setOnClickListener(this);
        mTimeTv.setOnClickListener(this);
        mPassReDeleted.setOnClickListener(this);
        mPassDeleted.setOnClickListener(this);


        /*监听密码：是否显示delet图标*/
        mPhoneEditor.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    mPhoneDeleted.setVisibility(View.VISIBLE);
                } else {
                    mPhoneDeleted.setVisibility(View.INVISIBLE);
                }
               // userPassword = s.toString().trim();
            }
        });
        mPasseEditor.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    mPassDeleted.setVisibility(View.VISIBLE);
                } else {
                    mPassDeleted.setVisibility(View.INVISIBLE);
                }
                // userPassword = s.toString().trim();
            }
        });
        mRePassEditor.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    mPassReDeleted.setVisibility(View.VISIBLE);
                } else {
                    mPassReDeleted.setVisibility(View.INVISIBLE);
                }
                // userPassword = s.toString().trim();
            }
        });
    }

    private void initView() {
        Button mBttonToRigest = findViewById(R.id.activity_rigest_go_login_bn);
        mBttonToRigest.setOnClickListener(this);

        mTimeTv=findViewById(R.id.ac_register_time_tv);
        mOverView=findViewById(R.id.ac_overscroll_soft_over);
        mPhoneEditor=findViewById(R.id.ac_rigister_phone);
        mPasseEditor=findViewById(R.id.ac_rigister_passworld);
        mRePassEditor=findViewById(R.id.ac_rigister_repassworld);

        mPhoneDeleted=findViewById(R.id.ac_login_right_img);
        mPassDeleted=findViewById(R.id.ac_loginpass_right_img);
        mPassReDeleted=findViewById(R.id.ac_loginrepass_right_img);




    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.activity_rigest_go_login_bn:
                startActivity(new Intent(this,RegisterActivityMy.class));
                break;
            case R.id.ac_register_time_tv:
                new Thread() {
                    public void run() {
                        //这里去发送短信
                    }
                }.start();
                tirmer.start();
                break;
            case R.id.ac_overscroll_soft_over:
                KeyBorderUtils.hideKeyboard(mOverView);
                break;
            case R.id.ac_login_right_img:
                mPhoneEditor.setText(null);
                break;
            case R.id.ac_loginpass_right_img:
                mPasseEditor.setText(null);
                break;
            case R.id.ac_loginrepass_right_img:
                mRePassEditor.setText(null);
                break;
        }

    }
}
